<?php

namespace MLM\Model\Member\Contact;

use MLM\Model\Member\Contact;

class Storage extends \MLM\Model\Generic\Db\Storage{
   public function save(Contact $contact){
        $insert = $this->_sql->insert()
                ->into('member_contact')
                ->values($contact->pull());
        
        $result = $this->execute($insert);
        
        return $result;
    }


    public function updateContact($data, $where){


        $update = $this->_sql->update();

        $update->table('contact');

        $update->set($data);

        $update->where($where);


        return $this->execute($update);
    }
    
    
    public function getMemberContact($key){
        
        $sql = "select *
                    from member_contact mc, contact c
                    where mc.member_id = ?
                    and c.contact_id = mc.contact_id ";


        
        $stmt = $this->_db->query($sql);
        $res = $stmt->execute(array($key));


        return $res;
    }


    public function getMemberContactByMobile($key){

        $sql = "select *
                    from member_contact mc, contact c
                    where c.contact_mobile = ?
                    and c.contact_id = mc.contact_id ";

        $stmt = $this->_db->query($sql);
        $res = $stmt->execute(array($key));


        return $res;
    }
}
